<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>吃什么</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <% include ../include/head.ejs %>
        <link rel="stylesheet" href="/stylesheets/mycss.css">
        <script>
            //新增爱好组
            function addGroup(){
                window.location.href = "./toAddGroup";
            }
            //删除爱好组
            function deleteGroup(groupId){
                $.ajax({
                    url:"./delGroup",
                    data:{groupId:groupId},
                    success:function(res){
                        if(res==="ok"){
                            $.toast("删除成功",500,function(){
                                location.reload();
                            });
                        }
                    },
                    error:function(){
                        $.toast("删除失败", "cancel");
                    }
                });
            }
            //编辑爱好组
            function updateGroup(groupId){
                window.location.href = "./toAddGroup";
            }
        </script>
    </head>
    <body>
        <header>
            <a href="/user"><i class="glyphicon glyphicon-chevron-left"></i></a>
        </header>
        <div class="weui-tab">
            <div class="weui-tab__bd">
                <div class="weui-tab__bd-item weui-tab__bd-item--active">
                    <div class="weui-cells__title">爱好组管理<a href="javascript:;" onclick="addGroup()"><span class="glyphicon glyphicon-plus-sign pull-right"></span></a></div>
                    <div class="weui-cells">
                        <% for(i in groups) {%>
                        <div class="weui-cell weui-cell_swiped" id="swipe1">
                            <div class="weui-cell__bd">
                                <div class="weui-cell">
                                    <div class="weui-cell__bd">
                                        <p><%=groups[i].groupName%></p>
                                    </div>
                                    <div class="weui-cell__ft">左滑修改</div>
                                </div>
                            </div>
                            <div class="weui-cell__ft">
                                <a class="weui-swiped-btn weui-swiped-btn_warn delete-swipeout" href="javascript:" onclick="deleteGroup(<%=groups[i].groupId %>)">删除</a>
                                <a class="weui-swiped-btn weui-swiped-btn_default close-swipeout" href="javascript:" onclick="updateGroup(<%=groups[i].groupId %>)">编辑</a>
                            </div>
                        </div>
                        <% } %>
                    </div>
                </div>
            </div>
        </div>
        <% include ../include/nav.ejs %>
        <% include ../include/head-js.ejs %>
    </body>
</html>